package android.xml;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

import android.model.BankItem;

public class BankHandler extends ItemsHandler<BankItem> {
	
	//konstanti koi soodvestvuvaat so tagovite vo xml dokumentot
	public static final String WORDS = "words";
	public static final String WORD = "word";
	public static final String DESCRIPTION = "description";

	/*
	 * (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#characters(char[], int, int)
	 * se dobiva izvestuvanje za podatocite vnatre vo dokumentot
	 */
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

		sb.append(ch,start,length);
	}

	/*
	 * (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
	 * se dobiva izvestuvanje koga ke se stigne do krajot na dokumentot
	 */
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		
		  if (WORD.equals(currentElement)) {
			currentItem.setWord(sb.toString().trim());
		} else if (DESCRIPTION.equals(currentElement)) {
			currentItem.setDescriprion(sb.toString().trim());
		}
		currentElement = null;
		 
	}

	/*
	 * (non-Javadoc)
	 * @see org.xml.sax.helpers.DefaultHandler#startElement
	 * (java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 * se dobiva izvestuvanje za pocetok na dokument
	 */
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		
		currentElement = localName;
		sb = new StringBuffer();
		if (WORDS.equals(currentElement)) {
			currentItem = new BankItem();
			items.add(currentItem);
		}
	}

}
